﻿using MiniFox.Scripting;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace MiniFox.Platform.Scripting
{
    /// <summary>
    /// 
    /// </summary>
    public class ClientInfoFunction : StateFunctionBase
    {
        /// <summary>
        /// 
        /// </summary>
        /// <param name="setting"></param>
        public ClientInfoFunction(IFunctionSetting setting) : base(setting)
        {
        }
        /// <summary>
        /// 
        /// </summary>
        /// <param name="arguments"></param>
        /// <returns></returns>
        protected override object Execute(IDictionary<string, object> arguments)
        {
            string field = arguments.Count <= 0 ? string.Empty : arguments["key"].ToString();
            Type type = this.StateManagement.ClientInfomation.GetType();
            var property = type.GetProperty(field);
            if (property == null)
                return null;
            object val = property.GetValue(this.StateManagement.ClientInfomation);
            return val;
        }
    }
}
